package com.enjia.common.view;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.StyleRes;
import android.view.Gravity;
import android.widget.TextView;

import com.enjia.enjiashop.R;


/**
 * 缓冲Dialog，可全局使用
 * Created by 陈飞飞 on 2017/10/23.
 */

public class CustomProgressDialog extends Dialog {
    //Dialog展示信息
    String message;

    public CustomProgressDialog(@NonNull Context context, String message) {
       this(context, R.style.CustomProgressDialog,message);
    }

    public CustomProgressDialog(@NonNull Context context, @StyleRes int themeResId, String message) {
        super(context, themeResId);
        this.message=message;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_customprogress);
        this.getWindow().getAttributes().gravity= Gravity.CENTER;
        TextView tvMeg= (TextView) this.findViewById(R.id.ProgressText);
        if(tvMeg!=null){
            tvMeg.setText(message);
        }
    }

    @Override
    public void onWindowFocusChanged(boolean hasFocus) {
        if(!hasFocus){
            dismiss();
        }
    }
}
